Passed
Push — master ( e44814...88e81d )
by Andreas
21:13
created

rcs.js ➔ init_controls   B

Complexity

Conditions 6

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 25
rs 8.6666
c 0
b 0
f 0
cc 6
1
function init_controls() 
2
{
3
    const form = $('form[name="midcom_admin_rcs_history"]');
4
    
5
    if (form.find('tbody').children().length < 2) {
6
        form.find('[name="first"], [name="last"], [name="f_compare"]').css('visibility', 'hidden');
7
        return;
8
    }
9
    
10
    if (form.find('[name="first"]:checked').length === 0) {
11
        form.find('[name="first"]').eq(0).trigger('click');
12
    }
13
    
14
    if (form.find('[name="last"]:checked').length === 0) {
15
        form.find('[name="last"]').eq(1).trigger('click');
16
    }
17
18
    form.on('change', '[name="first"]', function() {
19
        $('[name="f_compare"]').prop('disabled', $(this).val() == $('[name="last"]:checked').val());
20
    });
21
    
22
    form.on('change', '[name="last"]', function() {
23
        $('[name="f_compare"]').prop('disabled', $(this).val() == $('[name="first"]:checked').val());
24
    });
25
}